gold.lang.require('gold.framework.TestRunner');
gold.lang.require('gold.framework.SilentTestWriter');

gold.TestRunner.add('TestRunner Test', function() {
	var testRunner = null;
	return {
		'before': function() {
			var testWriter = new gold.framework.SilentTestWriter();
			testRunner = new gold.framework.TestRunner(testWriter);
		},
		testTestWithNamePrefixShouldBeRun: function() {
			var hasrun = false;
			testRunner.add('Test', {'testTest': function() { hasrun = true; } });
			testRunner.run();
			gold.assert(hasrun).isTrue();
		},
		testTestWithoutNamePrefixShouldNotBeRun: function() {
			var hasrun = false;
			testRunner.add('Test', {'ohai': function() { hasrun = true; } });
			testRunner.run();
			gold.assert(hasrun).isFalse();
		},
		testBeforeIsCalledBeforeEveryTest: function() {
			var before = 0;
			testRunner.add('Test', {'before': function() { before++; }, 'test1': function() {}, 'test2': function() {}});
			testRunner.run();
			gold.assert(before).equals(2);
		},
		testAfterIsCalledAfterEveryTest: function() {
			var after = 0;
			testRunner.add('Test', {'after': function() { after++; }, 'test1': function() {}, 'test2': function() {}});
			testRunner.run();
			gold.assert(after).equals(2);
		},
		testOnlyFunctionsAndObjectsAreLegalTestCases: function() {
			testRunner.add('Test', {});
			testRunner.add('Test', function() { return {}; });
			var expected = 'Testcase must be an object or a function that returns an object.';
			gold.assert(function() {
				testRunner.add('Test', function() {});
			}).doesThrow(expected);
			gold.assert(function() {
				testRunner.add('Test', null);
			}).doesThrow(expected);
		}
	};
});